// Marty Stepp, CSE 142 Winter 2008, Section XYZ // // This program draws a figure that looks like a mirror // using nested loops. // // This version does not have a constant, for comparison // purposes. The Mirror.java is a better example for HW2. public class MirrorWithoutConstant { public static void main(String[] args) { topHalf(); bottomHalf(); } // This method draws the top half of the mirror. public static void topHalf() { for (int line = 1; line <= 4; line++) { // | System.out.print("|"); // spaces for (int space = 1; space <= (-2 * line + 8); space++) { System.out.print(" "); } // <> System.out.print("<>"); // dots for (int dot = 1; dot <= (4 * line - 4); dot++) { System.out.print("."); } // <> System.out.print("<>"); // spaces for (int space = 1; space <= (-2 * line + 8); space++) { System.out.print(" "); } // | System.out.println("|"); } } // This method draws the bottom half of the mirror. public static void bottomHalf() { for (int line = 4; line >= 1; line--) { System.out.print("|"); for (int space = 1; space <= (-2 * line + 8); space++) { System.out.print(" "); } System.out.print("<>"); for (int dot = 1; dot <= (4 * line - 4); dot++) { System.out.print("."); } System.out.print("<>"); for (int space = 1; space <= (-2 * line + 8); space++) { System.out.print(" "); } System.out.println("|"); } } }